package com.dc.project_java.test.news;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.dc.base.ui.activity.BaseVmVbActivity;
import com.dc.project_java.databinding.ActivityNewsBinding;

public class NewsActivity extends BaseVmVbActivity<NewsViewModel, ActivityNewsBinding> {

    private NewsAdapter mAdapter;

    @Override
    protected void initView() {
        viewBinding.btnRequestData.setOnClickListener(v -> viewModel.requestData());
        mAdapter = new NewsAdapter(this);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        viewBinding.rvNews.setLayoutManager(manager);
        viewBinding.rvNews.setAdapter(mAdapter);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void createObserver() {
        viewModel.getNewsLiveData().observe(this, newsBean -> mAdapter.setDatas(newsBean.getStories()));
    }
}